#!/usr/bin/perl -w

use strict;

# declare...
sub trim($);

my @result = split(/\n/, `xm list`);

# remove the first line
shift(@result);
#shift(@result) while @result && $result[0] !~ /^[\t ]+Name/;
#shift(@result);

my $numid=0;

foreach my $line (@result) {
        my @xenInfo = split(/[\t ]+/, trim($line));

        if ( "$xenInfo[0]" ne "Domain-0" ) {
                if ( $ARGV[0] eq "name" ) { printf("%s\n", $xenInfo[0]); }
                if ( $ARGV[0] eq "cpu" ) { printf("%s\n", $xenInfo[3]); }
                if ( $ARGV[0] eq "mem" ) { printf("%s\n", $xenInfo[2]); }
                if ( $ARGV[0] eq "numid" ) { print ++$numid."\n"; }
        }
}


# trims leading and trailing whitespace
sub trim($)
{
  my $string = shift;
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  return $string;
}
